This activity will ask you to write several small functions, then use them to unscramble a message.
Some advice 🤝
Work in groups, maximum 2!
Google is your friend! If an error is confusing, copy it into Google and see what other people are saying. If you don’t know how to do something, search for it. You can use AI to help you understand code as well, but be critical of the outputs and always double check that it works.
Just because there is no error message, it doesn’t mean everything went smoothly. Use the console to check each step and make sure you have accomplished what you wanted to accomplish.
Document your process! Use the empty code chunks set-up for you. If you need more remember the keyboard shortcut is CTRL+ALT+I or CMD+ALT+I.
Part One: Create your functions
Many of the functions have been started for you below, but none of them are complete as-is.
Write a function called divide_and_round(), which takes a number or vector of numbers, divides them all by their smallest value, and rounds the results to the nearest whole number.
Write a function called no_nines_or_twelves(), which takes a number or vector of numbers and returns TRUE if the number is NOT divisible by 9 or 12, FALSE otherwise.
Write a function called every_other() which takes a vector and returns every other value in the vector.
Hint 🔍
You could achieve this with a for-loop but there are definitely more efficient ways to do it!
Include an optional argument called “start” which lets you choose where to start skipping; that is, if start = 1, we return the 1st value, 3rd, 5th, etc. and if start = 2, we return the 2nd, 4th, 6th, etc.
Write a function called shorten() which takes a vector and keeps dropping the first value, until the sum of the vector is less than 350 Return the remaining values.
Hint 🔍
You probably want to either use the cumsum() function, or write a while() loop.
Be sure to test your function.
shorten <-function(){}
Part Two: Your functions are the key
Once you have written your four functions correctly, run the following code:
If you have done everything correctly, your final vector will be six numbers long. Google these six numbers to find a TV show as your final answer.
Solution 🎉
Write the name of the TV show here.
Upload the .qmd doc and the rendered html to Blackboard (don’t forget to add all your teammates names!). The first team receives an extra point each in class participation 🏃
Appel, M., & Pebesma, E. (2019). On-demand processing of data cubes from satellite image collections with the gdalcubes library. Data, 4(3). https://www.mdpi.com/2306-5729/4/3/92
Appelhans, T., Detsch, F., Reudenbach, C., & Woellauer, S. (2023). Mapview: Interactive viewing of spatial data in r. https://github.com/r-spatial/mapview
Baddeley, A., & Turner, R. (2005). spatstat: An R package for analyzing spatial point patterns. Journal of Statistical Software, 12(6), 1–42. https://doi.org/10.18637/jss.v012.i06
Baddeley, A., Turner, R., Mateu, J., & Bevan, A. (2013). Hybrids of gibbs point process models and their implementation. Journal of Statistical Software, 55(11), 1–43. https://doi.org/10.18637/jss.v055.i11
Bivand, R., & Wong, D. W. S. (2018). Comparing implementations of global and local indicators of spatial association. TEST, 27(3), 716–748. https://doi.org/10.1007/s11749-018-0599-x
Câmara, G., Simoes, R., Souza, F., Pelletier, C., Sanchez, A., Andrade, P., Ferreira, K., & Queiroz, G. (2023). sits: Satellite image time series analysis on Earth observation data cubes. https://e-sensing.github.io/sitsbook/index.html
Dunnington, D., Vanderhaeghe, F., Caha, J., & Muenchow, J. (2024b). R package qgisprocess: Use QGIS processing algorithms. Version 0.4.1. https://r-spatial.github.io/qgisprocess/
Grolemund, G., & Wickham, H. (2011). Dates and times made easy with lubridate. Journal of Statistical Software, 40(3), 1–25. https://www.jstatsoft.org/v40/i03/
Hadley Wickham, J. B. (2023). R packages (2nd ed.). O’Reilly Media.
Pebesma, E. (2018). Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal, 10(1), 439–446. https://doi.org/10.32614/RJ-2018-009
Pebesma, E., & Graeler, B. (2024). Gstat: Spatial and spatio-temporal geostatistical modelling, prediction and simulation. https://github.com/r-spatial/gstat/
Plate, T., & Heiberger, R. (2024). Abind: Combine multidimensional arrays.
R Core Team. (2024). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/
Roger Bivand. (2022). R packages for analyzing spatial data: A comparative case study with areal data. Geographical Analysis, 54(3), 488–518. https://doi.org/10.1111/gean.12319
Rydzik, M. (2024, January 10). An Overview of the RSI R Package for Retrieving Satellite Imagery and Calculating Spectral Indices. https://geocompx.org/post/2024/rsi-bp1/
Simoes, R., Camara, G., Queiroz, G., Souza, F., Andrade, P., Santos, L., Carvalho, A., & Ferreira, K. (2021). Satellite image time series analysis for big earth observation data. Remote Sensing, 13(13), 2428. https://doi.org/10.3390/rs13132428
Simoes, R., Camara, G., Souza, F., & Carlos, F. (2024). Sits: Satellite image time series analysis for earth observation data cubes. https://github.com/e-sensing/sits/
Simoes, R., Souza, F., Zaglia, M., Queiroz, G. R., Santos, R., & Ferreira, K. (2021). Rstac: An r package to access spatiotemporal asset catalog satellite imagery. 2021 IEEE International Geoscience and Remote Sensing Symposium IGARSS, 7674–7677. https://doi.org/10.1109/IGARSS47720.2021.9553518
Spinu, V., Grolemund, G., & Wickham, H. (2023). Lubridate: Make dealing with dates a little easier. https://lubridate.tidyverse.org
Vuorre, M., & Crump, M. J. C. (2020). Sharing and organizing research products as r packages. Behavior Research Methods, 53(2), 792â802. https://doi.org/10.3758/s13428-020-01436-x
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686. https://doi.org/10.21105/joss.01686
Wickham, H., Bryan, J., Barrett, M., & Teucher, A. (2024). Usethis: Automate package and project setup. https://usethis.r-lib.org
Wickham, H., Çetinkaya-Rundel, M., & Grolemund, G. (2023). R for data science (2nd ed.). O’Reilly Media.
Wickham, H., Chang, W., Henry, L., Pedersen, T. L., Takahashi, K., Wilke, C., Woo, K., Yutani, H., Dunnington, D., & van den Brand, T. (2024). ggplot2: Create elegant data visualisations using the grammar of graphics. https://ggplot2.tidyverse.org
Wickham, H., Danenberg, P., Csárdi, G., & Eugster, M. (2024). roxygen2: In-line documentation for r. https://roxygen2.r-lib.org/
Wickham, H., François, R., Henry, L., Müller, K., & Vaughan, D. (2023). Dplyr: A grammar of data manipulation. https://dplyr.tidyverse.org
Wickham, H., Hesselberth, J., Salmon, M., Roy, O., & Brüggemann, S. (2024). Pkgdown: Make static HTML documentation for a package. https://pkgdown.r-lib.org/
Xie, Y. (2014). Knitr: A comprehensive tool for reproducible research in R. In V. Stodden, F. Leisch, & R. D. Peng (Eds.), Implementing reproducible computational research. Chapman; Hall/CRC.
Xie, Y. (2015). Dynamic documents with R and knitr (2nd ed.). Chapman; Hall/CRC. https://yihui.org/knitr/
Xie, Y. (2024). Knitr: A general-purpose package for dynamic report generation in r. https://yihui.org/knitr/